package qnb.controller;




import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;


import org.springframework.web.servlet.ModelAndView;
import qnb._common.easyui.EasyuiGridData;
import qnb._common.easyui.EasyuiPageVO;
import qnb._common.vo.MessageVOFactory;
import qnb.entity.Room;
import qnb.service.impl.RoomServiceImpl;
import weixinkeji.vip.jweb.power.ann.JWPIdentifiter;

@Controller
@RequestMapping("/room")
public class RoomController {
	@Autowired
	private RoomServiceImpl roomServiceImpl;
	/**
	 * 跳转到添加页面
	 * @return
	 */
	@JWPIdentifiter("room:add")
	@RequestMapping("/forward/add")
	public ModelAndView forwardtoRoomAdd(ModelAndView modelAndView) {
		modelAndView.setViewName("room/RoomAdd");
		return modelAndView;
	}
	/**
	 * 跳转到增删查改的页面
	 * @return
	 */
	@JWPIdentifiter("room:select")
	@RequestMapping("/forward/list")
	public ModelAndView forwardtoRoomList(ModelAndView modelAndView) {
		modelAndView.setViewName("room/RoomList");
		return modelAndView;
	}
	/**
	 * 处理页面添加的请求
	 * @param room
	 * @return
	 */
	@RequestMapping("/addRoom")
	@ResponseBody
	public String disposeRoomAdd(Room room) {
		if(roomServiceImpl.check_Name(room.getRoomName())!=null) {
			return "{\"msg\":\"添加失败:宿舍名称已存在,请重新输入!\"}";
		}
		return  MessageVOFactory.getAddMessage(roomServiceImpl.addRoom(room));
	}
	/**
	 * 发送数据，到数据表格填充
	 * @return
	 */
	@JWPIdentifiter("room:select")
	@RequestMapping("/selectRoom")
	@ResponseBody
	public Object dataFoDatagarid(EasyuiPageVO vo) {
		Object obj= EasyuiGridData.getEasyuiGridData(roomServiceImpl.sumCount(), roomServiceImpl.selectAll(vo.getStart(),vo.getRows()));
		JSON.toJSON(obj);
		return obj;
	}
	@JWPIdentifiter("room:update")
	@RequestMapping("/updateRoom")
	@ResponseBody
	public String update(Room room) {
		return MessageVOFactory.getUpdateMessage(roomServiceImpl.updateRoom(room));
	}

	@RequestMapping("/seOne")
	@ResponseBody
	public Room selectOne(int roomId) {
		return roomServiceImpl.selectToId(roomId);
	}

	@JWPIdentifiter("room:dell")
	@RequestMapping("/deleteRoom")
	@ResponseBody
	public String delete(int[]list) {
		return MessageVOFactory.getDellMessage(roomServiceImpl.deleteRoom(list));
	}
}
